<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">
    <ui:define name="head-title">
        <title>Make Payment for Customer | Merlion's ERP System</title>
    </ui:define>
    
    
    <ui:define name="content">
        <f:view beforePhase="#{addCustomerPaymentManagerBean.initView}">
        <h:form>
            <p:panel id="panel" header="Make Payment for Customer"> 
                <p:ajaxStatus style="width:16px;height:16px;">   
                    <f:facet name="start">   
                        <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                    </f:facet> 
 
                    <f:facet name="complete">   
                        <h:outputText value="" />   
                    </f:facet>   
                </p:ajaxStatus> 
 
                <p:messages /> 
                    
                    
                    <h:outputLabel for="customerName" style="font-weight: bold" value="Search Company: " /> 
                    <p:autoComplete value="#{addCustomerPaymentManagerBean.saleLeadName}" required="true"
                                    id="customerName" label="customerName" requiredMessage="Company Name is required." completeMethod="#{addCustomerPaymentManagerBean.complete}">
                    </p:autoComplete>
                        <p:message for="customerName" />                         
                        
                        
            <p:fieldset legend="List of Pending Invoices Information" rendered="#{addCustomerPaymentManagerBean.isExisting}">
                <h:panelGrid columns="6" cellpadding="10">      
                    <p:dataTable var="customerInvoice" value="#{addCustomerPaymentManagerBean.selectedCustomer.customerInvoice_Pending}"
                                     emptyMessage="No Pending Invoices found." style="width: 50%;" selection="#{addCustomerPaymentManagerBean.selectedCustomerInvoice}" >
                        
                    <p:column selectionMode="single"/>
                    <p:column sortBy="#{customerInvoice.customerInvoiceId}">
                        <f:facet name="header">
                            <h:outputText value="Customer Invoice ID"/>
                        </f:facet>
                        <h:outputText value="#{customerInvoice.customerInvoiceId}"/>
                    </p:column>

                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Date"/>
                        </f:facet>
                        <h:outputText value="#{customerInvoice.customerInvoiceDate}" style="width: 150px"/>
                    </p:column>
                    
                     <p:column>
                        <f:facet name="header">
                            <h:outputText value="Amount"/>
                        </f:facet>
                         <h:outputText value="#{customerInvoice.customerInvoiceAmount}" style="width: 150px"/>
                    </p:column>
                    
                     <p:column>
                        <f:facet name="header">
                            <h:outputText value="Sale Order ID"/>
                        </f:facet>
                         <h:outputText value="#{customerInvoice.saleOrder.id}" style="width: 150px"/>
                    </p:column>
                    
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Status"/>
                        </f:facet>
                        <h:outputText value="#{customerInvoice.stateCustomerInvoice}" style="width: 150px"/>
                    </p:column>
                        </p:dataTable>
                        
                        
                </h:panelGrid>
            </p:fieldset>                        
                
                        
                        <p:commandButton value="Retrieve Information" update="panel" actionListener="#{addCustomerPaymentManagerBean.retrieve}" ajax="true" rendered="#{addCustomerPaymentManagerBean.isNotExisting}"/>
                <p:commandButton id="btn" value="Make payment" update="panel" actionListener="#{addCustomerPaymentManagerBean.makePayment}" ajax="true" rendered="#{addCustomerPaymentManagerBean.isExisting}"/>
                
                <h:panelGrid columns="6" cellpadding="10" rendered="#{addCustomerPaymentManagerBean.isSelectedInvoice}">
                    <h:outputLabel for="paymentAmount" style="font-weight: bold" value="Payment Amount: " /> 
                    <h:inputText value="#{addCustomerPaymentManagerBean.paymentAmount}" id="paymentAmount"/>
                    
                    <p:commandButton value="Confirm payment" update="panel" actionListener="#{addCustomerPaymentManagerBean.confirmPayment}" ajax="true" />
                
                </h:panelGrid>                    
                
                </p:panel> 
        </h:form>
        </f:view>
        
    </ui:define>

</ui:composition>
